package handler.commandprocessor;

import handler.CommandHandler;
import io.netty.channel.ChannelHandlerContext;
import message.Command;
import message.command.SendToGroupCommand;
import route.Router;
import util.Constants;

public class SendToGroupProcessor implements CommandHandler.CommandProcessor
{
    private Router   router;

    public SendToGroupProcessor(Router router)
    {
        this.router = router;
    }

    @Override
    public void process(Command command, ChannelHandlerContext ctx)
    {
        String groupName = ((SendToGroupCommand) command).getGroupName();
        String msg       = ((SendToGroupCommand) command).getMsg();
        String clientId  = ctx.channel().attr(Constants.CLIENT_ID).get();
        router.sendToGroup(groupName, clientId, msg);
    }
}
